<?php

/**
 * Created by PhpStorm.
 * User: evan
 * Date: 16/9/1
 * Time: 下午6:02
 */
class Profile extends MY_Admin_Controller
{
    public function index()
    {
        $staffInfo = $this->uInfo;

        $this->load->model('staff/Model_staff_depart','depart');
        $departInfo = $this->depart->getAllLists();

        $data = array(
            'staffInfo'     =>    $staffInfo,
            'departInfo'    =>    $departInfo
        );
        $this->load->view('admin/user/profile/create',$data);
    }


    public function modify()
    {

    }

    public  function save()
    {
        $sid = (int)$this->uInfo['sid'];

        //图片未存入
        $data = array(
            'did'         =>      (int)$this->input->get_post('did'),
            'realname'    =>      trim($this->input->get_post('realname')),
            'mobile'      =>      $this->input->get_post('mobile'),
            'email'       =>      trim($this->input->get_post('email')),
            'qq'          =>      trim($this->input->get_post('qq')),
            'sex'         =>      (int)$this->input->get_post('sex'),
            'id_card'     =>      (int)$this->input->get_post('id_card'),
            'descr'       =>      trim($this->input->get_post('descr')),
            'is_quit'     =>      (int)$this->input->get_post('is_quit'),
        );

        //更新
        $this->load->model('staff/model_staff','staff');
        $this->staff->save($data, ($sid ? $sid : null));

        $this->load->helper('url');
        redirect(url('admin').'base/index');
    }


    public function modify_header()
    {
        $this->load->view('admin/user/profile/create_header');
    }

    public function save_header()
    {
        $sid = (int)$this->uInfo['sid'];

        //图片未存入
        $data = array(
            //判断是否选择图片如果选择了图片则获取新突破地址或者判断是新建页面还是修改页面
            'header'           =>     !empty($_FILES['up_file']['tmp_name'])?$this->uploadFile('up_file'):(isset($sid)?$this->input->get_post('pic'):''),
        );

        //更新
        $this->load->model('staff/model_staff','staff');
        $this->staff->save($data, $sid ? $sid : null);

        $this->load->helper('url');
        redirect(url('admin').'base/index');
    }


    public function modify_password()
    {
    	$this->load->view('admin/user/profile/modify_password');
    }
    
    public function save_password()
    {
    	$sid = (int)$this->uInfo['sid'];
    	$password = md5($this->input->get_post('password'));
    	
    	$data = array('password'=>$password);
    	
    	//更新
    	$this->load->model('staff/model_staff','staff');
    	$this->staff->save($data, $sid ? $sid : null);
    
    	$this->load->helper('url');
    	redirect(url('admin').'base/index');
    }
}